package netty.nio;

import netty.common.Constant;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author cyt
 * @create 2020-11-04 14:18
 */
public class TestB {

    public static void main(String[] args) throws IOException {
        /**
         * 得到一个本地文件的通道
         */
        File file = new File(Constant.FILEPATH + "channel.txt");
        FileChannel channel = new FileInputStream(file).getChannel();
        /**
         * 定义一个内存块， 并且把通道中的数据写入到内存块中
         */
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        int read = channel.read(buffer);
        System.out.println(read);
        String str = new String(buffer.array());
        System.out.println(str);

    }
}
